package dhm.com.dhmshop.view.mine.myshop;

        import android.os.Bundle;
        import android.support.v7.widget.LinearLayoutManager;
        import android.support.v7.widget.RecyclerView;
        import android.widget.TextView;
        import android.widget.Toast;

        import com.facebook.drawee.view.SimpleDraweeView;

        import java.text.DecimalFormat;
        import java.util.HashMap;
        import java.util.Map;

        import butterknife.BindView;
        import butterknife.ButterKnife;
        import butterknife.OnClick;
        import dhm.com.dhmshop.R;
        import dhm.com.dhmshop.adapter.mine.DetailordersAdapter;
        import dhm.com.dhmshop.base.BaseActiity;
        import dhm.com.dhmshop.base.Presenter.PressenterImpl;
        import dhm.com.dhmshop.base.netWork.Constant;
        import dhm.com.dhmshop.base.netWork.LoginContract;
        import dhm.com.dhmshop.entity.GetUserInfo;
        import dhm.com.dhmshop.entity.Orderdetail;
        import dhm.com.dhmshop.utils.SpUtils;
        import dhm.com.dhmshop.view.home.OrderdetailActivity;

public class ShoporderdActivity extends BaseActiity implements LoginContract.IView {

    @BindView(R.id.image)
    SimpleDraweeView image;
    @BindView(R.id.name)
    TextView name;
    @BindView(R.id.recy)
    RecyclerView recy;
    @BindView(R.id.money)
    TextView money;
    @BindView(R.id.line1)
    TextView line1;
    @BindView(R.id.addr)
    TextView addr;
    @BindView(R.id.orderId)
    TextView orderId;
    @BindView(R.id.creattime)
    TextView creattime;
    @BindView(R.id.paytime)
    TextView paytime;
    private String uid;
    private String order_id;
    private PressenterImpl pressenter;
    private DetailordersAdapter detailordersAdapter;


    @Override
    protected int getLayout() {
        return R.layout.activity_shoporderd;
    }

    @Override
    protected void initView() {
        ButterKnife.bind(this);
        pressenter=new PressenterImpl();
        pressenter.attachView(this);

        LinearLayoutManager manager=new LinearLayoutManager(this);
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        recy.setLayoutManager(manager);
        detailordersAdapter = new DetailordersAdapter(this);
        recy.setAdapter(detailordersAdapter);
        uid = getIntent().getStringExtra("uid");
        order_id = getIntent().getStringExtra("order_id");
        Map<String,String> map=new HashMap<>();
        map.put("token", Constant.TOKEN);
        map.put("uid",uid);
        map.put("order_id",order_id);

        pressenter.sendMessage(this,Constant.OrderDetail,map, Orderdetail.class);


    }

    @Override
    protected void initData() {

    }

    @OnClick(R.id.back)
    public void onViewClicked() {
        finish();
    }

    @Override
    public void requesta(Object data) {
        if (data instanceof Orderdetail){
            Orderdetail orderdetail= (Orderdetail) data;
            if (orderdetail.getCode()==1){
                userinfo(orderdetail.getData().getUserId()+"");
                creattime.setText(orderdetail.getData().getCreateTime());
                paytime.setText(orderdetail.getData().getPayTime());
                orderId.setText(orderdetail.getData().getOrderNo());
                addr.setText(orderdetail.getData().getShopAddress());
                detailordersAdapter.setShopList(orderdetail.getData().getGoods());

                /*Double price=Double.parseDouble(orderdetail.getData().get(0).getPrice())*Integer.parseInt(orderdetail.getData().get(0).getCount());
                DecimalFormat decimalFormat=new DecimalFormat("0.00");
                String resultString=decimalFormat.format(price);*/
                money.setText("￥"+orderdetail.getData().getRealTotalMoney());
            }else {
                Toast.makeText(this, orderdetail.getMessage(), Toast.LENGTH_SHORT).show();
                finish();
            }

        }else if (data instanceof GetUserInfo){
            GetUserInfo getUserInfo= (GetUserInfo) data;
            image.setImageURI(Constant.PATH+"/"+getUserInfo.getData().getHeadsmall());
            name.setText(getUserInfo.getData().getUser_nickname());
        }

    }

    protected void userinfo(String uid) {
        Map<String,String> map=new HashMap<>();
        map.put("token",Constant.TOKEN);
        map.put("uid",uid);
        pressenter.sendMessage(ShoporderdActivity.this, Constant.GetUserInfo,map, GetUserInfo.class);

    }

    @Override
    public void fail(String error) {

    }
}
